<?php

/*
  Action- Attack $5

  +2 cards
  Each other player with at least 4 cards in hand discards 1 action card from their hand, or reaveal a hand with no Action cards

 */

class Blogger extends Card implements iAction, iKingdom, iAddiction, iAttack {

    public function __construct() {
        parent::__construct("Blogger", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2 cards",
            "  Each other player with at least 4 cards in hand discards 1 action card from their hand, or reaveal a hand with no Action cards.");
    }

    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(2);
        ScreenDisplay::addScreenMessage($game, true, "draw ".  nicePrint($drawed_cards), "draws ".sizeof($drawed_cards)." cards");
        $game->attack($this);


        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize > 3) {
                $actionCards = array();
                foreach ($playHandOther as $otherCard) {
                    if ($otherCard instanceof iAction) {
                        $actionCards[] = $otherCard;
                    }
                }
                if (sizeof($actionCards) == 0) {
                    ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($playHandOther) . " with no actions", "reveals " . nicePrint($playHandOther) . " with no actions", $name);
                } else if (sizeof($actionCards) == 1) {
                    $game->moveCardFromPileToPile($actionCards[0], PlayHand, DiscardPile, $name);
                    ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($actionCards), "discards " . sizeof($actionCards) . " card", $name);
                } else {
                    $output = MySocket::GetUserReply($game, Input_ChooseMany, $actionCards, 1, 1, null, "Choose action card to discard", $name, true);
                }
            }
        }
        
        $game->setPhase(Phase_Sleep);
        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {

            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, DiscardPile, $name);
            }
            ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($output), "discards " . sizeof($output) . " cards", $name);
            $game->setPhase(Phase_Sleep, $name);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>